import { getAction, deleteAction, putAction, postAction, httpAction } from '@/api/manage'
import Vue from 'vue'
import {UI_CACHE_DB_DICT_DATA } from "@/store/mutation-types"

////根路径
// const doMian = "/jeecg-boot/";
////图片预览请求地址
// const imgView = "http://localhost:8080/jeecg-boot/sys/common/view/";

//角色管理
const addRole = (params)=>postAction("/sys/role/add",params);
const editRole = (params)=>putAction("/sys/role/edit",params);
// const getRoleList = (params)=>getAction("/sys/role/list",params);
// const deleteRole = (params)=>deleteAction("/sys/role/delete",params);
// const deleteRoleList = (params)=>deleteAction("/sys/role/deleteBatch",params);
const checkRoleCode = (params)=>getAction("/sys/role/checkRoleCode",params);
const queryall = (params)=>getAction("/sys/role/queryall",params);

//用户管理
const addUser = (params)=>postAction("/sys/user/add",params);
const editUser = (params)=>putAction("/sys/user/edit",params);
const queryUserRole = (params)=>getAction("/sys/user/queryUserRole",params);
const getUserList = (params)=>getAction("/sys/user/list",params);
// const deleteUser = (params)=>deleteAction("/sys/user/delete",params);
// const deleteUserList = (params)=>deleteAction("/sys/user/deleteBatch",params);
const frozenBatch = (params)=>putAction("/sys/user/frozenBatch",params);
//验证用户是否存在
const checkOnlyUser = (params)=>getAction("/sys/user/checkOnlyUser",params);
//改变密码
const changePassword = (params)=>putAction("/sys/user/changePassword",params);

//权限管理
const addPermission= (params)=>postAction("/sys/permission/add",params);
const editPermission= (params)=>putAction("/sys/permission/edit",params);
const getPermissionList = (params)=>getAction("/sys/permission/list",params);
/*update_begin author:wuxianquan date:20190908 for:添加查询一级菜单和子菜单查询api */
const getSystemMenuList = (params)=>getAction("/sys/permission/getSystemMenuList",params);
const getSystemSubmenu = (params)=>getAction("/sys/permission/getSystemSubmenu",params);
const getSystemSubmenuBatch = (params) => getAction('/sys/permission/getSystemSubmenuBatch', params)
/*update_end author:wuxianquan date:20190908 for:添加查询一级菜单和子菜单查询api */

// const deletePermission = (params)=>deleteAction("/sys/permission/delete",params);
// const deletePermissionList = (params)=>deleteAction("/sys/permission/deleteBatch",params);
const queryTreeList = (params)=>getAction("/sys/permission/queryTreeList",params);
const queryTreeListForRole = (params)=>getAction("/sys/role/queryTreeList",params);
const queryListAsync = (params)=>getAction("/sys/permission/queryListAsync",params);
const queryRolePermission = (params)=>getAction("/sys/permission/queryRolePermission",params);
const saveRolePermission = (params)=>postAction("/sys/permission/saveRolePermission",params);
//const queryPermissionsByUser = (params)=>getAction("/sys/permission/queryByUser",params);
const queryPermissionsByUser = (params)=>getAction("/sys/permission/getUserPermissionByToken",params);
const loadAllRoleIds = (params)=>getAction("/sys/permission/loadAllRoleIds",params);
const getPermissionRuleList = (params)=>getAction("/sys/permission/getPermRuleListByPermId",params);
const queryPermissionRule = (params)=>getAction("/sys/permission/queryPermissionRule",params);

// 部门管理
const queryDepartTreeList = (params)=>getAction("/sys/sysDepart/queryTreeList",params);
const queryIdTree = (params)=>getAction("/sys/sysDepart/queryIdTree",params);
const queryParentName   = (params)=>getAction("/sys/sysDepart/queryParentName",params);
const searchByKeywords   = (params)=>getAction("/sys/sysDepart/searchBy",params);
const deleteByDepartId   = (params)=>deleteAction("/sys/sysDepart/delete",params);

//二级部门管理
const queryDepartPermission = (params)=>getAction("/sys/permission/queryDepartPermission",params);
const saveDepartPermission = (params)=>postAction("/sys/permission/saveDepartPermission",params);
const queryTreeListForDeptRole = (params)=>getAction("/sys/sysDepartPermission/queryTreeListForDeptRole",params);
const queryDeptRolePermission = (params)=>getAction("/sys/sysDepartPermission/queryDeptRolePermission",params);
const saveDeptRolePermission = (params)=>postAction("/sys/sysDepartPermission/saveDeptRolePermission",params);
const queryMyDepartTreeList = (params)=>getAction("/sys/sysDepart/queryMyDeptTreeList",params);

//日志管理
//const getLogList = (params)=>getAction("/sys/log/list",params);
const deleteLog = (params)=>deleteAction("/sys/log/delete",params);
const deleteLogList = (params)=>deleteAction("/sys/log/deleteBatch",params);

//数据字典
const addDict = (params)=>postAction("/sys/dict/add",params);
const editDict = (params)=>putAction("/sys/dict/edit",params);
//const getDictList = (params)=>getAction("/sys/dict/list",params);
const treeList = (params)=>getAction("/sys/dict/treeList",params);
// const delDict = (params)=>deleteAction("/sys/dict/delete",params);
//const getDictItemList = (params)=>getAction("/sys/dictItem/list",params);
const addDictItem = (params)=>postAction("/sys/dictItem/add",params);
const editDictItem = (params)=>putAction("/sys/dictItem/edit",params);
//const delDictItem = (params)=>deleteAction("/sys/dictItem/delete",params);
//const delDictItemList = (params)=>deleteAction("/sys/dictItem/deleteBatch",params);

//字典标签专用（通过code获取字典数组）
export const ajaxGetDictItems = (code, params)=>getAction(`/sys/dict/getDictItems/${code}`,params);
//从缓存中获取字典配置
function getDictItemsFromCache(dictCode) {
  if (Vue.ls.get(UI_CACHE_DB_DICT_DATA) && Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode]) {
    let dictItems = Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode];
    console.log("-----------getDictItemsFromCache----------dictCode="+dictCode+"---- dictItems=",dictItems)
    return dictItems;
  }
}

//系统通告
const doReleaseData = (params)=>getAction("/sys/annountCement/doReleaseData",params);
const doReovkeData = (params)=>getAction("/sys/annountCement/doReovkeData",params);
//获取系统访问量
const getLoginfo = (params)=>getAction("/sys/loginfo",params);
const getVisitInfo = (params)=>getAction("/sys/visitInfo",params);
//数据日志访问
// const getDataLogList = (params)=>getAction("/sys/dataLog/list",params);

// 根据部门主键查询用户信息
const queryUserByDepId = (params)=>getAction("/sys/user/queryUserByDepId",params);

// 查询用户角色表里的所有信息
// const queryUserRoleMap = (params)=>getAction("/sys/user/queryUserRoleMap",params);
// 重复校验
const duplicateCheck = (params)=>getAction("/sys/duplicate/check",params);
// 加载分类字典
const loadCategoryData = (params)=>getAction("/sys/category/loadAllData",params);
const checkRuleByCode = (params) => getAction('/sys/checkRule/checkByCode', params)
//加载我的通告信息
const getUserNoticeInfo= (params)=>getAction("/sys/sysAnnouncementSend/getMyAnnouncementSend",params);
const getTransitURL = url => `/sys/common/transitRESTful?url=${encodeURIComponent(url)}`

//流程处理
const getTodoList = (params)=> getAction('/workflow/waitDone/list', params)

//社团管理
const getSocietyList = (params)=> getAction('/org/society/list', params)
const updateSociety = (params)=> postAction('/org/society/add', params)
const getSocietyById = (params)=> getAction('/org/society/queryById', params)
const delSociety= (params)=> deleteAction('/org/society/delete', params)
const addSocietyMember = (params)=> postAction('/org/societyUser/add', params)
const getSocietyMemberList = (params)=> getAction('/org/societyUser/list', params)
const getSocietyMemberById = (params)=> getAction('/org/societyUser/queryById', params)
const delSocietyMembers= (params)=> deleteAction('/org/societyUser/deleteBatch', params)

//校级学生组织
const getOrganizationList = (params)=> getAction('/org/stdGroup/list', params)
const addOrganization = (params)=> postAction('/org/stdGroup/add', params)
const getOrganizationById = (params)=> getAction('/org/stdGroup/queryById', params)
const delOrganization= (params)=> deleteAction('/org/stdGroup/delete', params)
const delOrganizations= (params)=> deleteAction('/org/stdGroup/deleteBatch', params)
const getOrganizationMemberList = (params)=> getAction('/org/stdGroupUser/list', params)
const addOrganizationMember = (params)=> postAction('/org/stdGroupUser/add', params)
const getOrganizationMemberById = (params)=> getAction('/org/stdGroupUser/queryById', params)
const delOrganizationMember= (params)=> deleteAction('/org/stdGroupUser/delete', params)
const delOrganizationMembers= (params)=> deleteAction('/org/stdGroupUser/deleteBatch', params)

//青年志愿者
const getVolunteerTeams = (params)=> getAction('/volunteerTeam/list', params)
const setVolunteerTeam= (params)=> postAction('/volunteerTeam/add', params)
const delVolunteerTeam= (params)=> deleteAction('/volunteerTeam/delete', params)
const delVolunteerTeams= (params)=> deleteAction('/volunteerTeam/deleteBatch', params)
const getVolunteerTeamById = (params)=> getAction('/volunteerTeam/queryById', params)
const setVolunteerTeamMember = (params)=> postAction('/volunteerTeamUser/add', params)
const getVolunteerTeamMembers = (params)=> getAction('/volunteerTeamUser/list', params)
const getVolunteerTeamMemberById = (params)=> getAction('/volunteerTeamUser/queryById', params)
const delVolunteerTeamMember= (params)=> deleteAction('/volunteerTeamUser/delete', params)
const delVolunteerTeamMembers= (params)=> deleteAction('/volunteerTeamUser/deleteBatch', params)

//科研项目
const getProjects = (params)=> getAction('/researchProject/list', params)
const getProjectsMyList = (params)=> getAction('/researchProject/myList', params)
const setProject = (params)=> postAction('/researchProject/add', params)
const delProject = (params)=> deleteAction('/researchProject/delete', params)
const getProjectById = (params)=> getAction('/researchProject/queryById', params)

//场地物资
const getMaterials = (params)=> getAction('/material/list', params)
const setMaterial = (params)=> postAction('/material/add', params)
const delMaterial = (params)=> deleteAction('/material/delete', params)
const delMaterials = (params)=> deleteAction('/material/deleteBatch', params)
const getMaterialById = (params)=> getAction('/material/queryById', params)

const getMaterialApplys = (params)=> getAction('/materialApply/list', params)
const setMaterialApply = (params)=> postAction('/materialApply/add', params)
const delMaterialApply = (params)=> deleteAction('/materialApply/delete', params)
const delMaterialApplys = (params)=> deleteAction('/materialApply/deleteBatch', params)
const getMaterialApplyById = (params)=> getAction('/materialApply/queryById', params)

//经费
const getFundApply = (params)=> getAction('/fundApply/list', params)
const setFundApply = (params)=> postAction('/fundApply/add', params)
const delFundApply = (params)=> deleteAction('/fundApply/delete', params)
const delBatchFundApply= (params)=> deleteAction('/fundApply/deleteBatch', params)
const getFundApplyById = (params)=> getAction('/fundApply/queryById', params)

//流程
const getWorkflow = (params)=> getAction('/workflow/queryFlowNodeDataByBizId', params)

// 校外活动申请
const setoutside = (params)=> postAction('/outsideActivity/add', params)
// 校外活动申请-分页列表查询
const setoutsideList = (params)=> getAction('/outsideActivity/list', params)
const delsetoutside = (params)=> deleteAction('/outsideActivity/delete', params)
const setoutsideByid = (params)=> getAction('/outsideActivity/queryById', params)

// 中转HTTP请求
export const transitRESTful = {
  get: (url, parameter) => getAction(getTransitURL(url), parameter),
  post: (url, parameter) => postAction(getTransitURL(url), parameter),
  put: (url, parameter) => putAction(getTransitURL(url), parameter),
  http: (url, parameter) => httpAction(getTransitURL(url), parameter),
}

export {
  getFundApply,
  setFundApply,
  delFundApply,
  delBatchFundApply,
  getFundApplyById,
  getMaterialApplys,
  setMaterialApply,
  delMaterialApply,
  delMaterialApplys,
  getMaterialApplyById,
  getMaterials,
  setMaterial,
  delMaterial,
  delMaterials,
  getMaterialById,
  getProjects,
  getProjectsMyList,
  setProject,
  delProject,
  getProjectById,
  delSociety,
  delSocietyMembers,
  delOrganization,
  delOrganizations,
  delOrganizationMember,
  delOrganizationMembers,
  delVolunteerTeam,
  delVolunteerTeams,
  delVolunteerTeamMember,
  delVolunteerTeamMembers,
  getVolunteerTeams,
  setVolunteerTeam,
  getVolunteerTeamById,
  setVolunteerTeamMember,
  getVolunteerTeamMembers,
  getVolunteerTeamMemberById,
  getOrganizationMemberById,
  addOrganizationMember,
  getOrganizationMemberList,
  getOrganizationById,
  getSocietyMemberById,
  getSocietyById,
  // imgView,
  // doMian,
  addRole,
  editRole,
  checkRoleCode,
  addUser,
  editUser,
  queryUserRole,
  getUserList,
  queryall,
  frozenBatch,
  checkOnlyUser,
  changePassword,
  getPermissionList,
  addPermission,
  editPermission,
  queryTreeList,
  queryListAsync,
  queryRolePermission,
  saveRolePermission,
  queryPermissionsByUser,
  loadAllRoleIds,
  getPermissionRuleList,
  queryPermissionRule,
  queryDepartTreeList,
  queryIdTree,
  queryParentName,
  searchByKeywords,
  deleteByDepartId,
  deleteLog,
  deleteLogList,
  addDict,
  editDict,
  treeList,
  addDictItem,
  editDictItem,
  doReleaseData,
  doReovkeData,
  getLoginfo,
  getVisitInfo,
  queryUserByDepId,
  duplicateCheck,
  queryTreeListForRole,
  getSystemMenuList,
  getSystemSubmenu,
  getSystemSubmenuBatch,
  loadCategoryData,
  checkRuleByCode,
  queryDepartPermission,
  saveDepartPermission,
  queryTreeListForDeptRole,
  queryDeptRolePermission,
  saveDeptRolePermission,
  queryMyDepartTreeList,
  getUserNoticeInfo,
  getDictItemsFromCache,
  getTodoList,
  getSocietyList,
  updateSociety,
  getOrganizationList,
  addOrganization,
  addSocietyMember,
  getSocietyMemberList,
  getWorkflow,
  setoutside,
  setoutsideList,
  delsetoutside,
  setoutsideByid
}



